'use strict';
/**
 * CarController
 * @constructor
 */
app.controller('ProcessController',['$scope','$http',function($scope, $http){
	$scope.fetchCarsList = function() {
        $http.get('process/list').success(function(datas){
            $scope.datas = datas;
        });
    };
    $scope.choseArr=[];//定义数组用于存放前端显示
    $scope.removeObject = function() {
        alert("here");
        $.scope.data = {
                param: JSON.stringify($scope.choseArr)
            };
        $http.delete('service/processService.delete/list.json' + angular.toJSON($scope.choseArr)).success(function() {
            $scope.fetchstoresList();
        }).error(function() {
            $scope.setError('Could not remove store');
        });
        $scope.store.name = '';
        $scope.store.speed = '';
    };

    $scope.startProcess = function(defId){
    	alert(defId);
    	$http({
    		url:'process/start',
    		method:'post',
    		params:{
    			"defId":defId
    		}
    	}).success(function(data){
    		
    	});
    }

    $scope.removeObject = function(id) {
     
    	 $http.delete('process/remove/' + id).success(function() {
             $scope.fetchCarsList();
         }).error(function() {
             $scope.setError('Could not remove train');
         });

    };
    
    var str="";
    $scope.chk=function(z,x){
    	
    	if(x==true){
    		str = str + z + ',';
    	}else{
    		 str = str.replace(z + ',', ',');//取消选中
    	}
    	$scope.choseArr=(str.substr(0,str.length-1)).split(',');
    }
    $scope.fetchCarsList();
}]);

app.controller('ProcessDetailCtrl', ['$scope',  '$stateParams','$http',function($scope,  $stateParams,$http) {
	$http({ url: 'process/readResouce?processDefinitionId='+$stateParams.defId, method: "POST",responseType: 'arraybuffer'}).success(function (data, status, headers, config) { 
		 $scope.xml = data;
	});
	
	}]);
app.controller('ProcessStartCtrl', ['$scope',  '$stateParams','$http',function($scope,  $stateParams,$http) {

	$http.get('process/start?id='+$stateParams.defId).success(function(datas){
        $scope.datas = datas;
    });
	$scope.startProcess = function(processDefinition) {
        $http.post('process/startProcess', JSON.stringify(processDefinition)).success(function() {
            $scope.fetchTrainsList();
           
        }).error(function() {
            $scope.setError('Could not add a new train');
        });
    };
	}]);
